local skynet = require "skynet"
local filelog = require "filelog"
local msghelper = require "authsvrhelper"
require "enum"
local  AuthsvrReglogin = {}

--[[
//请求登陆注册服务器
message RegLoginReq {
	optional Version version = 1;
	optional int32 auth_type = 2;
	optional string user_name = 3;
	optional string cpass = 4;
    optional string regmobileid = 5; // 注册设备id
    optional string option_data = 6; // 可选数据	
}

//响应登陆注册服务器
message RegLoginRes {
	optional int32 errcode = 1;    //错误原因 0表示成功
	optional string errcodedes = 2;//错误描述	
	optional int32 uid = 3;        //账号uid
	optional int32 expiretime = 4; //过期时间戳
	optional string token = 5;     //登陆游戏服务器的认证token
}
]]
function  AuthsvrReglogin.process(session, source, fd, request)
	local responsemsg = {
		errcode = EErrCode.ERR_SUCCESS,
	}
	local server = msghelper.get_server()
	if request == nil or request.version == nil then
		responsemsg.errcode = EErrCode.ERR_INVALID_REQUEST
		responsemsg.errcodedes = "无效的请求！"
		msghelper:send_resmsgto_client(fd, "RegLoginRes", responsemsg)
		server.tcpmng.close_socket(fd)
		return
	end

	if request.auth_type ~= EauthType.AUTH_TYPE_GUEST 
		and request.auth_type ~= EauthType.AUTH_TYPE_WECHAT
		and request.auth_type ~= EauthType.AUTH_TYPE_SELF then
		responsemsg.errcode = EErrCode.ERR_INVALID_AUTHTYPE
		responsemsg.errcodedes = "无效的账号类型！"
		msghelper:send_resmsgto_client(fd, "RegLoginRes", responsemsg)
		server.tcpmng.close_socket(fd)
		return		
	end

	if request.user_name == nil or request.cpass == nil then
		responsemsg.errcode = EErrCode.ERR_INVALID_REQUEST
		responsemsg.errcodedes = "无效的请求，参数错误！"
		msghelper:send_resmsgto_client(fd, "RegLoginRes", responsemsg)
		server.tcpmng.close_socket(fd)
		return		
	end
	
	server.tcpmng.create_session(fd, "RegLoginReq", request)
end

return AuthsvrReglogin
